home *** CD-ROM | disk | FTP | other *** search
- Path: news.magi.com!news!news.magi.com
- From: nredding@magi.com (Neil Redding)
- Newsgroups: comp.lang.c
- Subject: Re: char* string problem
- Date: Sat, 06 Jan 1996 10:48:18 -0500
- Organization: Magi Data Consulting
- Message-ID: <nredding-0601961048180001@magi03p09.magi.com>
- References: <4ci7gu$68r@cloner3.netcom.com> <820846052snz@intellic.demon.co.uk>
- NNTP-Posting-Host: magi03p09.magi.com
-
- In article <820846052snz@intellic.demon.co.uk>,
- truemanc@intellic.demon.co.uk wrote:
-
- >In article <4ci7gu$68r@cloner3.netcom.com>
- > tstevens@ix.netcom.com "Edward Stevens " writes:
- >
- >> I need to prepend some switch characters to some strings passed
- >>to a main program which I have renamed for use as a function.
- >>
- >>The calling program looks like this:
- >>
- >>char* the_args[4];
- >>char* Aprefix = " -A";
- >>char* Bprefix = " -B";
- >>char* CPrefix = " -C";
- >>char* Dprexix = " -D";
- >>
- >>the_args[0] = "user_name";
- >>the_args[0] = strcat(Aprefix,the_args[0]);
- >
- >Your problem is that the_args[0] is being set to the address of
- >Aprefix which points to three (3) blocks of memory. By executing the
- >strcat you are overwriting memory you have not already allocated.
- >
- > - Chris
- You are also attempting to modify a string constant , Aprefix, which is a no-no.
- If you want to modify Aprefix, you should declare it as an array, not a
- char pointer.
-
- --
- Neil Redding
- Ottawa, Canada
-